<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>精美弹窗窗口</title>
    <style>
        /* 全局样式重置与字体设置 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            overflow: hidden;
        }

        /* 按钮样式 */
        .open-btn {
            padding: 12px 24px;
            background-color: #fff;
            color: #667eea;
            border: none;
            border-radius: 30px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
            transition: all 0.3s ease;
            z-index: 10;
        }

        .open-btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
        }

        .open-btn:active {
            transform: translateY(0);
        }

        /* 遮罩层样式 */
        .modal-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
            display: flex;
            justify-content: center;
            align-items: center;
            opacity: 0;
            visibility: hidden;
            transition: opacity 0.3s ease, visibility 0.3s ease;
            z-index: 1000;
        }

        .modal-overlay.active {
            opacity: 1;
            visibility: visible;
        }

        /* 弹窗主体样式 */
        .modal {
            background-color: #fff;
            width: 400px;
            max-width: 90vw;
            border-radius: 16px;
            overflow: hidden;
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            transform: scale(0.8);
            opacity: 0;
            transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
        }

        .modal-overlay.active .modal {
            transform: scale(1);
            opacity: 1;
        }

        /* 弹窗头部 */
        .modal-header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            font-size: 18px;
            font-weight: 600;
        }

        /* 关闭按钮 */
        .close-btn {
            background: rgba(255, 255, 255, 0.2);
            color: white;
            border: none;
            width: 30px;
            height: 30px;
            border-radius: 50%;
            font-size: 16px;
            cursor: pointer;
            display: flex;
            justify-content: center;
            align-items: center;
            transition: background 0.3s ease;
        }

        .close-btn:hover {
            background: rgba(255, 255, 255, 0.3);
        }

        /* 弹窗内容区 */
        .modal-body {
            padding: 25px;
            color: #444;
            line-height: 1.6;
        }

        .modal-title {
            font-size: 20px;
            color: #333;
            margin-bottom: 12px;
            text-align: center;
        }

        .modal-content {
            font-size: 15px;
            color: #666;
            margin-bottom: 20px;
        }

        /* 表单输入框 */
        .input-group {
            margin-bottom: 18px;
        }

        .input-group label {
            display: block;
            margin-bottom: 6px;
            font-weight: 500;
            color: #555;
            font-size: 14px;
        }

        .input-group input {
            width: 100%;
            padding: 12px 15px;
            border: 1px solid #ddd;
            border-radius: 8px;
            font-size: 15px;
            transition: border-color 0.3s ease;
            outline: none;
        }

        .input-group input:focus {
            border-color: #667eea;
            box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
        }

        /* 弹窗底部按钮区域 */
        .modal-footer {
            padding: 15px 25px 25px;
            display: flex;
            justify-content: flex-end;
            gap: 10px;
        }

        .btn {
            padding: 10px 20px;
            border: none;
            border-radius: 8px;
            font-size: 14px;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .btn-cancel {
            background-color: #e0e0e0;
            color: #555;
        }

        .btn-cancel:hover {
            background-color: #d0d0d0;
        }

        .btn-confirm {
            background-color: #667eea;
            color: white;
        }

        .btn-confirm:hover {
            background-color: #5a6fd8;
            transform: translateY(-2px);
            box-shadow: 0 4px 10px rgba(102, 126, 234, 0.3);
        }

        /* 响应式设计 */
        @media (max-width: 480px) {
            .modal {
                width: 90vw;
            }

            .modal-body {
                padding: 20px;
            }

            .modal-footer {
                flex-direction: column;
            }

            .btn {
                width: 100%;
                justify-content: center;
            }
        }
    </style>
</head>
<body>
<!-- 触发弹窗的按钮 -->
<button class="open-btn">打开弹窗</button>

<!-- 弹窗遮罩层 -->
<div class="modal-overlay">
    <div class="modal">
        <!-- 弹窗头部 -->
        <div class="modal-header">
            <div>信息填写</div>
            <button class="close-btn">&times;</button>
        </div>

        <!-- 弹窗内容 -->
        <div class="modal-body">
            <h3 class="modal-title">欢迎使用弹窗系统</h3>
            <p class="modal-content">请填写以下信息，我们将为您保存。所有数据仅在本地使用，不会上传至服务器。</p>

            <!-- 表单输入 -->
            <div class="input-group">
                <label for="name">姓名</label>
                <input type="text" id="name" placeholder="请输入您的姓名">
            </div>
            <div class="input-group">
                <label for="email">邮箱</label>
                <input type="email" id="email" placeholder="请输入您的邮箱">
            </div>
        </div>

        <!-- 弹窗底部按钮 -->
        <div class="modal-footer">
            <button class="btn btn-cancel">取消</button>
            <button class="btn btn-confirm">确认提交</button>
        </div>
    </div>
</div>

<script>
    // 获取DOM元素
    const openBtn = document.querySelector('.open-btn');
    const modalOverlay = document.querySelector('.modal-overlay');
    const closeBtn = document.querySelector('.close-btn');
    const cancelBtn = document.querySelector('.btn-cancel');
    const confirmBtn = document.querySelector('.btn-confirm');
    const modal = document.querySelector('.modal');

    // 打开弹窗函数
    function openModal() {
        modalOverlay.classList.add('active');
        // 防止页面滚动
        document.body.style.overflow = 'hidden';
    }

    // 关闭弹窗函数
    function closeModal() {
        modalOverlay.classList.remove('active');
        // 恢复页面滚动
        document.body.style.overflow = '';
    }

    // 点击打开按钮时打开弹窗
    openBtn.addEventListener('click', openModal);

    // 点击关闭按钮时关闭弹窗
    closeBtn.addEventListener('click', closeModal);

    // 点击取消按钮时关闭弹窗
    cancelBtn.addEventListener('click', closeModal);

    // 点击确认按钮时的处理
    confirmBtn.addEventListener('click', function() {
        const name = document.getElementById('name').value;
        const email = document.getElementById('email').value;

        // 简单的验证
        if (name.trim() === '') {
            alert('请输入姓名！');
            return;
        }

        if (email.trim() === '' || !email.includes('@')) {
            alert('请输入有效的邮箱地址！');
            return;
        }

        // 模拟提交成功
        alert(`提交成功！\n姓名：${name}\n邮箱：${email}`);
        closeModal();

        // 清空表单
        document.getElementById('name').value = '';
        document.getElementById('email').value = '';
    });

    // 点击遮罩层外部关闭弹窗
    modalOverlay.addEventListener('click', function(e) {
        if (e.target === modalOverlay) {
            closeModal();
        }
    });

    // 键盘事件处理
    document.addEventListener('keydown', function(e) {
        // ESC键关闭弹窗
        if (e.key === 'Escape' && modalOverlay.classList.contains('active')) {
            closeModal();
        }

        // Enter键确认提交（当焦点不在输入框时）
        if (e.key === 'Enter' && modalOverlay.classList.contains('active')) {
            const activeElement = document.activeElement;
            if (activeElement !== document.getElementById('name') &&
                activeElement !== document.getElementById('email')) {
                confirmBtn.click();
            }
        }
    });

    // 动画优化：确保在关闭动画完成后才真正隐藏
    modalOverlay.addEventListener('transitionend', function() {
        if (!modalOverlay.classList.contains('active')) {
            // 确保关闭动画完成后执行
        }
    });

    // 防止弹窗内部点击事件冒泡到遮罩层
    modal.addEventListener('click', function(e) {
        e.stopPropagation();
    });
</script>
</body>
</html>